<?php
class Application_Model_DbTable_Reponse extends Zend_Db_Table_Abstract{
	protected $_name = 'reponse';
	protected $primary = array('id_qcm','num_quest','num_rep');
	
	public function fetchAllByQuestion($qcm_id,$quest_num){
		$select = $this->select();
		$select->setIntegrityCheck(false);
		
		$select	->from(array('q'=>$this->_name))
				->where('q.id_qcm = ?',$qcm_id)
				->where('q.num_quest = ?',$quest_num);
		$result = $select->query()->fetchAll(PDO::FETCH_OBJ);
		return $result;
	}
	public function nextID($qcm_id,$num_quest){
		$select = $this->select();
		
		$select ->from(array('q'=>$this->_name),'MAX(num_rep) as max')
				->where('q.id_qcm = ?',$qcm_id)
				->where('q.num_quest = ?',$num_quest);
		return ($select->query()->fetch(PDO::FETCH_OBJ)->max +1);
	}
	public function find($qcm_id,$num_quest,$num_rep){
		$select = $this->select();
		$select->setIntegrityCheck(false);
		
		$select	->from(array('q'=>$this->_name))
				->where('q.id_qcm = ?',$qcm_id)
				->where('q.num_quest = ?',$num_quest)
				->where('q.num_rep = ?',$num_rep);
		return $select->query()->fetch(PDO::FETCH_OBJ);
	}
}